/*
 * QWidgetActionAdapter.cpp  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "QWidgetActionAdapter.h"

// QWidgetActionAdapter :: Public Constructor. ---------------------------------

/*!
 * \brief Constructs new QWidgetActionAdapter object.
 *
 * \param parent the parent object
 */
QWidgetActionAdapter::QWidgetActionAdapter(ComponentDelegate *parent)
  : QWidgetAction(parent)
{
  Q_ASSERT(parent);
}

/*!
 * \brief Destroys the QWidgetActionAdapter object.
 */
QWidgetActionAdapter::~QWidgetActionAdapter()
{
  // empty destructor body
  setDefaultWidget(0);
}

// QWidgetActionAdapter :: Protected Member Function. --------------------------

/*!
 * \brief Returns parent delegate.
 *
 * \return parent delegate
 */
ComponentDelegate *QWidgetActionAdapter::parentDelegate()
{
  return qobject_cast<ComponentDelegate *>(parent());
}

// QWidgetActionAdapter :: Overridden Member Functions. ------------------------

/*!
 * \inheritDoc
 */
QWidget *QWidgetActionAdapter::createWidget(QWidget *parent)
{
  QWidget *widget = parentDelegate()->qWidget();
  setDefaultWidget(widget);
  widget->setParent(parent);
  return widget;
}

/*!
 * \inheritDoc
 */
void QWidgetActionAdapter::deleteWidget(QWidget *widget)
{
  setDefaultWidget(0);
  widget->setParent(0);
  parentDelegate()->widgetActionDeleted(this);
}
